#ifndef MOVINGOBJECT_H
#define MOVINGOBJECT_H
#include <d3dx9.h>
#include <math.h>
#include "Steering.h"
#include "Vector3D.h"
#include "enumPack.h"


//Added an f to the end of this PI so as to avoid a truncation error
//For some reason it keeps recognizing PI as a double so this sets it to float
//Brandon York - Koza
#define PI 3.141f

class Steering;

class MovingObject
{
private:
	Vector3D v3Position;	//the current position of the object
	float fSpeed;			//the maximum speed (scalar) that the object can go
	float fAngle;			//the angle representing the object's current heading in radians
	float fDesiredAngle;	//the angle representing the way the object should be heading

	//strenalis also has to make flags to determine which steering behavior is actually on. ie SeekOn();
	bool isSeeking;
	bool isFleeing;
	bool isEvading;
	bool isPursuing;


	Vector3D v3Velocity;	//velocity as a vector; this value is determined by the various steering functions and should only be set using those functions
	Vector3D v3Accel;		//acceleration as a vector; this value will be used in some steering functions

	//these are pointers to the various target's our object might have
	MovingObject* mopSeekTarget;
	MovingObject* mopFleeTarget;
	MovingObject* mopEvadeTarget;
	MovingObject* mopPursuitTarget;
	Steering mySteering;	//pointer to this object's steering behaviors

	int iShape;				//a flag that DirectX will understand what shape to give this object

public:
	//constructor with no parameters
	MovingObject(): mySteering(this) {v3Position.setCoord(0, 0, 0); v3Velocity = v3Accel = v3Position; fSpeed = 5; fAngle = 0; fDesiredAngle = 0;
										iShape = TRIANGLE;
										isSeeking = isFleeing = isEvading = isPursuing = false;
										D3DXMatrixTranslation(&d3dPosition, v3Position.getX(), v3Position.getY(), v3Position.getZ());
										/*D3DXMatrixTranslation(&d3dTarget, v3Target.getX(), v3Target.getY(), v3Target.getZ());*/}
										//we shouldn't need the above translation matrix anymore - Strog

	///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	////Koza Temp Constructor
	////Allows me to tell the differnce between the two
	//MovingObject(MovingObject* Target): mySteering(this) {v3Position.setCoord(0, 0, 0); v3Velocity = v3Accel = v3Position; fSpeed = 5; fAngle = 0;
	//								D3DXMatrixTranslation(&d3dPosition, v3Position.getX(), v3Position.getY(), v3Position.getZ());
	//								/*D3DXMatrixTranslation(&d3dTarget, v3Target.getX(), v3Target.getY(), v3Target.getZ()) ,PursuitTarget = Target;*/}
	/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

	D3DXMATRIX d3dPosition; //the current position of the object in a format that DirectX can use
	D3DXMATRIX d3dTarget;	//the target position of the object in a format that DirectX can use
	D3DXMATRIX d3dAngle;	//the angle the object is facing in a format that DirectX can use

	//each set function is overloaded so user can either pass a vector, or an x, y, z coordinate
	void setPosition(Vector3D pos);										
	void setPosition(float x, float y, float z);
	void setSpeed(float v) { fSpeed = v; }
	void setVelocity(Vector3D vel) { v3Velocity = vel; }
	void setVelocity(float x, float y, float z) { v3Velocity.setCoord(x, y, z); }
	void setAccel(Vector3D a) {v3Accel = a; }
	void setAccel(float x, float y, float z) {v3Accel.setCoord(x, y, z); }
	void setSeekTarget(MovingObject* tar) { mopSeekTarget = tar; }
	void setFleeTarget(MovingObject* tar) { mopFleeTarget = tar; }
	void setEvadeTarget(MovingObject* tar) { mopEvadeTarget = tar; }
	void setPursuitTarget(MovingObject* tar) { mopPursuitTarget = tar; }
	//void setTarget(Vector3D tar);
	//void setTarget(float x, float y, float z);
	void setAngle(float theta);
	void setDesiredAngle(float theta) { fDesiredAngle = theta; }
	void setShape(int newShape) {iShape = newShape; }

	//get functions
	Vector3D getPosition() { return v3Position; }
	float getSpeed() { return fSpeed; }
	Vector3D getVelocity() { return v3Velocity; }
	Vector3D getAccel() { return v3Accel; }
	MovingObject* getSeekTarget() {return mopSeekTarget;}
	MovingObject* getFleeTarget() {return mopFleeTarget;}
	MovingObject* getEvadeTarget() {return mopEvadeTarget;}
	MovingObject* getPursuitTarget() {return mopPursuitTarget;}
	//Vector3D getTarget() { return v3Target; }
	float getAngle() { return fAngle; }
	float getDesiredAngle() { return fDesiredAngle; }
	int getShape() { return iShape; }

	//steering flag functions
	void SeekOn() { if(mopSeekTarget) isSeeking = true; }
	void FleeOn() { if(mopFleeTarget)isFleeing = true; }
	void EvadeOn() { if(mopEvadeTarget)isEvading = true; }
	void PursuitOn() { if(mopPursuitTarget)isPursuing = true; }
	void SeekOff() { isSeeking = false; }
	void FleeOff() { isFleeing = false; }
	void EvadeOff() { isEvading = false; }
	void PursuitOff() { isPursuing = false; }

	void Update(float dt);
	void Calculate();
	bool isAtTarget(Vector3D);


	//Functions added to use added information///////////////////////////////////////
	
	/////////////////////////////////////////////////////////////////////////////////
};

#endif